package TUILayer;
import java.util.Scanner;
import ControlLayer.DVDCtr;
/**
 * User interface to the DVD controller
 * @author(kbh)
 * @version(2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2008.10.24: dvdmenu changed to If                   
 */

public class DvdUI
{
    private DVDCtr dvdCtr;//DVD UI must know the DVD controller 
    
    public DvdUI()
    {
        dvdCtr = new DVDCtr();
    }
    
    public void start()
    {
        dvdMenu();
    }
    
    public void updateMenu()
    {
        boolean exit = false;
        while(!exit)
        {
            int choice = writeUpdateMenu();
            if (choice == 1)
            {
                updateTitle();
            }
            else{if(choice == 2){
                updateDescription();
            } 
            else{if(choice == 3)
                {
                    updateGenre();
                }
                else{
                    exit = true;
                }//end else
                }// end else
            }// end else
            }//end else
    }// end while
    public void dvdMenu()
    {   
        boolean exit = false;
        while(!exit)
        {
            //show menu and return the user's choise
            int choice =   writeDVDMenu();
            if (choice == 1)
            {
                findDvd();
            }
            else{if(choice == 2){
                   createDVD();
                }
                else{
                    if(choice == 3){
                        createCopy();
                    }
                    else{
                        if(choice == 4){
                             deleteDVD();
                        }
                        else{
                            if(choice == 5){
                                listAllDvds();
                            }
                            else{
                                if(choice == 6){
                                    updateMenu();
                                }
                                else{
                                exit = true;
                            }
                            }//end else
                        }//end else
                    }//end else
                }//end else
            }//end else
            
        }//end while
    }
    private int writeDVDMenu()
    {
           // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** DVD Menu ***");
            System.out.println(" (1) Show DVD information");
            System.out.println(" (2) Create DVD ");
            System.out.println(" (3) Create DVD Copy");
            System.out.println(" (4) Delete DVD");
            System.out.println(" (5) Show current DVD list");
            System.out.println(" (6) Update Dvds");
            System.out.println(" (7) Exit ");
            System.out.print("\n Make your choice: ");
            
            int choice = keyboard.nextInt();
            return choice;
    }
    private int writeUpdateMenu()
    {
        //Creates an object keyboard to read the data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** Dvd update menu ***");
        System.out.println(" (1) Update Title");
        System.out.println(" (2) Update Description");
        System.out.println(" (3) Update Genre");
        //System.out.println(" (4) Update Copy");
        System.out.println(" (4) Return ");
        System.out.println("\n Make your choice: ");
        
        int choice = keyboard.nextInt();
        return choice;
    }
    private String inputGenre()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD Genre: ");
        String g = keyboard.nextLine();
        return g;
    }      
    private String inputTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }
    private String inputDescription()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type a short description: ");
        String d = keyboard.nextLine();
        return d;
    }
    private String inputID()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please choose an ID");
        String i = keyboard.nextLine();
        return i;
    }
    private String inputCopyNr()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please choose a copy number for your copy");
        String cnr = keyboard.nextLine();
        return cnr;
    }
       private String inputYear()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please choose the year the copy was made");
        String y = keyboard.nextLine();
        return y;
    }
    private double inputPrice()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please choose a price");
        double p = keyboard.nextDouble();
        return p;
    }
        
    private void findDvd()
    {
        String id = inputID();
        dvdCtr.printDvdInfo(id);
        waitInput();
    }
    
    private void updateDescription()
    {
        String id = inputID();
        String newDescription = inputDescription();
        dvdCtr.updateDescription(id, newDescription);
    }
    private void updateTitle()
    {
        String id = inputID();
        String newTitle = inputTitle();
        dvdCtr.updateTitle(id, newTitle);
    }
    private void updateGenre()
    {
        String id = inputID();
        String newGenre = inputGenre();
        dvdCtr.updateGenre(id, newGenre);
        waitInput();
    }
    private void createDVD()
    {
        String genre = inputGenre();
        String title = inputTitle();
        String description = inputDescription();
        String id = inputID();
        dvdCtr.createDVD(genre, title, description, id);
        waitInput();
    }
    private void createCopy()
    {
      String copyNr = inputCopyNr();
      String id = inputID();
      String year = inputYear();
      double price = inputPrice();
      dvdCtr.createCopy(id, copyNr, year, price);
      waitInput();
    }
    private void deleteDVD()
    {
        String id = inputID();
        dvdCtr.deleteDVD(id);
        waitInput();
    }
    private void listAllDvds()
    {
        dvdCtr.printAllDvds();
        waitInput();
    }
    private void waitInput()
    {
        System.out.println("Press enter to continue");
        new Scanner(System.in).nextLine();
    }
}
